from openai import OpenAI
client = OpenAI(
    base_url='http://localhost:11434/v1/',
    api_key='xxxxxx', #实际上本地模型不需要api_key
)

completion = client.chat.completions.create(
    messages=[
        {
            'role': 'user',
            'content': '段子赏析：爱一个人的眼神是藏不住的，爱两个人就一定要藏住。',
        }
    ],
    model='llama3.2:latest',
    stream=True  # add this line to enable streaming output
)
from IPython.display import display,clear_output
response = ""
for chunk in completion:
    response += chunk.choices[0].delta.content
    print(response)
    clear_output(wait=True)



